home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 114 / macaddict114.cdr / Software / Utilities / macam.0.8.4.dmg / macam sources / texts / SPCA504A_Aiptek_MegaCam.txt < prev    next >
Encoding:
Text File  |  2002-07-12  |  8.2 KB  |  195 lines

  1. A glance at the SPCA504A / Aiptek MiniCam 1.3
  2. ---------------------------------------------
  3.  
  4.  
  5. The cam registers as a composite device. There are two interfaces: The irst one has the standard control pipe and an isochronous IN pipe. This interface is probably used for live camera applications. The second interface has the standard control pipe, a bulk in pipe (for reading data from the cam), a bulk out pipe (for sending data to the cam - I don't know if this is supported with the Aiptek firmware) and an interrupt pipe (for camera events - can we read the button?). 
  6.  
  7. The remainder of this text is just about the second interface. For downloading images, only the control pipe and the bulk in pipe are used.
  8.  
  9. ----------------------------------------------------------------------------------------------------------
  10.  
  11.  
  12. There seem to be registers that can be read and set. The chip register base address seems to be 0x2000. The registers seem to be similar to those of the SPCA500A (except that their base address is 0x8000)
  13.  
  14. Write register
  15. --------------
  16.  
  17. Control request (vendor,interface,out) req:0x00 value:0x00aa index:0xbbbb len=0 (aa=value, bbbb=register address)
  18.  
  19. Read register
  20. -------------
  21.  
  22. Control reauest (vendor,interface,out) req:0x00 value:0x0000 index:0xbbbb len=1 (bbbb=register address) -> returns value
  23.  
  24. According to the SPCA500A specs, register blocks are:
  25.  
  26. 0x2000 - 0x20ff : global control registers
  27. 0x2100 - 0x21ff : CDSP (image processing) control registers
  28. 0x2200 - 0x22ff : TG (timing generator) control registers
  29. 0x2300 - 0x23ff : Post buffer (transfer memory) control registers 
  30. 0x2400 - 0x24ff : Flash memory control registers
  31. 0x2500 - 0x25ff : USB control registers
  32. 0x2600 - 0x26ff : Audio control registers
  33. 0x2700 - 0x27ff : DRAM control registers
  34. 0x2800 - 0x28ff : JPEG control registers
  35. 0x2900 - 0x29ff : CPU control registers
  36. 0x2a00 - 0x2aff : Synchronous control registers
  37. 0x3000 - 0x9fff?: Internal SRAM test registers / Test mode (???)
  38.  
  39. The win driver accesses the following banks:
  40.  
  41. global:     0x2000 is set to 0x00 at the very start
  42. post buffer:    0x2301 is set to 0x13 on start. 0x2306 is set to 0x00 (not directly) before and to 0x01 after the image data transfer
  43. USB control:    0x2501 is set to 0x01 once (not directly) before the data transfer.
  44. JPEG control:     The banks from 0x2800 to 0x283f and 0x2840 to 0x287f are set (interleavedly) - this would match setting of the Y and C quantization matrices
  45.  
  46. There seem to be more sensible commands than getting and setting registers (although they have a request code other than 0x00).
  47.  
  48. ----------------------------------------------------------------------------------------------------------
  49.  
  50.  
  51. Guesses about the communication to/from the camera:
  52.  
  53.  
  54. OP                        guess (very hypothetical)
  55. ----------------------------------------------------------------------------------------------------------
  56.  
  57. 1. General startup
  58. ------------------
  59.  
  60. set reg 0x2000 to 0x00                upload operation mode (SPCA500=idle?)
  61. set reg 0x2301 to 0x13                usb reads flash, post buffer data port 1
  62.                         (precisely: flash memory -> usb)
  63.  
  64. set reg 0x2800-0x287f                set quantization tables: Y (0x2800-283f) and C (0x2840-0x287f)
  65. 0x2501 -> 0x01                    accept EP0 packet? (whatever...)
  66. 0x2306 -> 0x00                    No corresponding register in SPCA500, must be something new :)
  67.  
  68. set reg 0x2501 to 0x01                ???
  69. set reg 0x2306 to 0x00                ???
  70.  
  71.                         addresses 0x0000 - 0x0fff = 
  72.                         Access to the firmware-controlled Microcontroller 4K-DRAM?
  73.  
  74. out: req 0x08 val 0x0000 idx 0x0006        ???
  75. in:  req 0x01 val 0x0000 idx 0x0001 len 1     called repeatedly - status request / wait for 0x86
  76.                         You have wo wait a bit inside the loop -
  77.                         sleep(1) is slow but works
  78.  
  79. out: req 0x01 val 0x0000 idx 0x000f        ???
  80.  
  81.  
  82. I don't understand the following block of communication -
  83. I guess it's for data not stored on Flash memory but in volatile RAM or for cams with other firmware.
  84. I also issue this commands and ignore the results - just because the win driver does them...
  85.  
  86. in:  req 0x0b val 0x0000 idx 0x0000 len 2    ask for number of objects
  87.                         (little endian, result is images * 2 - thumb + image?)
  88. out: req 0x0a val 0x00zz idx 0x000c        zz = number returned from previous call
  89. in : req 0x0b val 0x0000 idx 0x0004 len 1    query bulk transfer status: 1 = transfer ready, 0 otherwise
  90.  
  91. Bulk read as in "Get TOC" (see below)
  92.  
  93. in : req 0x01 val 0x0000 idx 0x0005 len 1
  94. in : req 0x01 val 0x0001 idx 0x0005 len 1
  95. in : req 0x01 val 0x0002 idx 0x0005 len 1
  96. in : req 0x01 val 0x0003 idx 0x0005 len 1
  97. in : req 0x01 val 0x0000 idx 0x0005 len 1
  98. in : req 0x01 val 0x0001 idx 0x0005 len 1
  99.  
  100. ----------------------------------------------------------------------------------------------------------
  101.  
  102. 2. Get TOC
  103. ----------
  104.  
  105. in:  req 0x0b val 0x0000 idx 0x0000 len 2    ask for number of objects
  106.                         (little endian, result is images * 2 - thumb + image?)
  107. out: req 0x0a val 0x00zz idx 0x000c        zz = number returned from previous call
  108.                         Request buld read of TOC
  109. in : req 0x0b val 0x0000 idx 0x0004 len 1    query bulk transfer status: 1 = transfer ready, 0 otherwise
  110.                         You have wo wait a bit inside the loop -
  111.                         sleep(1) is slow but works
  112.  
  113. Bulk read (in blocks of 256 bytes)
  114. It seems that you have to download the whole TOC. If it doesn't fit exactly, the rest of the last block is filled with junk.
  115.  
  116.  
  117. ----------------------------------------------------------------------------------------------------------
  118.  
  119. 3. Get Image
  120. ------------
  121.  
  122. in : req 0x0b val 0x0000 idx 0x0005 len 1    Same as "Get Thumbnail"
  123. in : req 0x01 val 0x0040 idx 0x0005 len 1    Same as "Get Thumbnail"
  124. out: req 0x0a val 0x00zz idx 0x000d        Request bulk read of image zz
  125. in : req 0x0b val 0x0000 idx 0x0004 len 1    Same as "Get TOC"
  126.  
  127. Bulk read (in blocks of 256 bytes). You can get the JPEG file length from the TOC entry. However, the camera tends to send more data than necessary. If you don't read all sent data, you are in trouble because you will get junk in the next bulk read. I don't know how the win driver finds out the exact amount to read (it seems to know that). I currently issue the read commands with a timeout of 0.3 seconds - if they time out, the pipe is clear.
  128.  
  129. ----------------------------------------------------------------------------------------------------------
  130.  
  131. 4. Get Thumbnail
  132. ----------------
  133.  
  134. in : req 0x0b val 0x0000 idx 0x0005 len 1    Some sort of status request - should return 0x20
  135. in : req 0x01 val 0x0040 idx 0x0005 len 1    Some sort of status request - should return 0x00
  136. out: req 0x0c val 0x00zz idx 0x0006        Request bulk read of thumbnail zz
  137. in : req 0x0b val 0x0000 idx 0x0004 len 1    Same as "Get TOC"
  138.  
  139. Bulk read (in blocks of 256 bytes)
  140. I haven't tried this, but it seems that you have to do the same read thing as in "Get Image".
  141.  
  142. ----------------------------------------------------------------------------------------------------------
  143.  
  144. 5. Shutdown
  145. -----------
  146.  
  147. set reg 0x2306 to 0x01                Cleanup
  148. set reg 0x0d04 to 0x00                Cleanup
  149.  
  150.  
  151. ----------------------------------------------------------------------------------------------------------
  152.  
  153. TOC format
  154. ----------
  155.  
  156. It seems that the TOC is a structure with a 32 byte entry for each entry:
  157.  
  158. Offset        Length        Guessed meaning
  159. 0x00        4        "Magic number" - Always ASCII "SUNP" 
  160. 0x04        4        ASCII four digit number
  161. 0x08        4        Format - either "THM " or "JPG "
  162. --- the first three entries form an ASCII file name ---
  163.  
  164. 0x0c        2        For JPG: Width of image in pixels (little endian), for THM: 0x0000
  165. 0x0e        2        For JPG: Height of image in pixels (little endian), for THM: 0x0000
  166. 0x10        4        Unknown 1 - 0x00000000 in all of my cases
  167. 0x14        4        Unknown 2 - 0x00000000 in all of my cases
  168. 0x18        4        start address (little endian)
  169. 0x1c        4        length (little endian)
  170.  
  171. ----------------------------------------------------------------------------------------------------------
  172.  
  173. Thumbnail format
  174. ----------------
  175.  
  176. ???
  177.  
  178. ----------------------------------------------------------------------------------------------------------
  179.  
  180. Image format
  181. ------------
  182.  
  183. The images are plain JPEG image files. You can store them and read them directly. Thanks, Sunplus!
  184.  
  185. ----------------------------------------------------------------------------------------------------------
  186.  
  187. Timing
  188. ------
  189.  
  190. The device seems to be a bit timing sensitive. Sometimes, you cannot issue the commands too fast. I.E. wait-for-ready loops had to be slowed down in my experiments in order not to crash the firmware. I added a sleep(1) into the two waiting 
  191.  
  192.  
  193. Matthias Krauß
  194.  
  195.